package com.starry.module.system.core.oauth2.controller.admin;

import cn.hutool.http.HttpStatus;
import com.starry.core.common.domain.R;
import com.starry.core.common.domain.vo.PageVo;
import com.starry.core.web.core.controller.BaseController;
import com.starry.module.system.api.oauth2.domain.qo.Oauth2ThirdClientPageQo;
import com.starry.module.system.api.oauth2.domain.qo.Oauth2ThirdClientQo;
import com.starry.module.system.api.oauth2.domain.vo.Oauth2ThirdClientDtlVo;
import com.starry.module.system.api.oauth2.domain.vo.Oauth2ThirdClientListVo;
import com.starry.module.system.api.oauth2.domain.vo.Oauth2ThirdClientVo;
import com.starry.module.system.core.oauth2.service.Oauth2ThirdClientService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Set;

/**
 * 第三方客户端
 *
 * @author xiaoke
 */
@Tag(name = "第三方客户端")
@RestController
@RequestMapping("system/oauth2ThirdClient")
public class Oauth2ThirdClientController extends BaseController {

    private final Oauth2ThirdClientService oauth2ThirdClientService;

    public Oauth2ThirdClientController(Oauth2ThirdClientService oauth2ThirdClientService) {
        this.oauth2ThirdClientService = oauth2ThirdClientService;
    }

    /**
     * 分页查询
     *
     * @param pageQo 查询实体
     * @return 所有数据
     */
    @Operation(summary = "第三方客户端-分页查询")
    @GetMapping("oauth2ThirdClientPage")
    public R<PageVo<Oauth2ThirdClientVo>> findPage(Oauth2ThirdClientPageQo pageQo) {
        return success(this.oauth2ThirdClientService.page(pageQo));
    }

    /**
     * 详情
     *
     * @param id 主键
     * @return 单条数据
     */
    @Operation(summary = "第三方客户端-详情")
    @GetMapping("oauth2ThirdClientDetails/{id}")
    public R<Oauth2ThirdClientDtlVo> findById(@PathVariable("id") Long id) {
        return success(this.oauth2ThirdClientService.getById(id));
    }

    /**
     * 新增数据
     *
     * @param oauth2ThirdClientQo 实体对象
     * @return 新增结果
     */
    @Operation(summary = "第三方客户端-新增")
    @PostMapping("oauth2ThirdClientCreate")
    public R<Long> insert(@RequestBody @Validated Oauth2ThirdClientQo oauth2ThirdClientQo) {
        return success(HttpStatus.HTTP_CREATED, this.oauth2ThirdClientService.save(oauth2ThirdClientQo));
    }

    /**
     * 修改数据
     *
     * @param oauth2ThirdClientQo 实体对象
     * @return 修改结果
     */
    @Operation(summary = "第三方客户端-修改")
    @PostMapping("oauth2ThirdClientUpdate")
    public R<Void> update(@RequestBody @Validated Oauth2ThirdClientQo oauth2ThirdClientQo) {
        this.oauth2ThirdClientService.updateById(oauth2ThirdClientQo);
        return success();
    }

    /**
     * 列表
     *
     * @return 所有数据
     */
    @Operation(summary = "第三方客户端-列表")
    @GetMapping("oauth2ThirdClientList")
    public R<List<Oauth2ThirdClientListVo>> getClientList() {
        return success(this.oauth2ThirdClientService.getClientList());
    }

    /**
     * 删除数据
     *
     * @param idList 主键集合
     * @return Void
     */
    @Operation(summary = "第三方客户端-删除")
    @PostMapping("oauth2ThirdClientRemove")
    public R<Void> delete(@RequestParam("idList") Set<Long> idList) {
        this.oauth2ThirdClientService.removeByIds(idList);
        return success();
    }

    /**
     * 启用数据
     *
     * @param idList 主键集合
     * @return Void
     */
    @Operation(summary = "第三方客户端-启用")
    @PostMapping("oauth2ThirdClientEnable")
    public R<Void> enable(@RequestParam("idList") Set<Long> idList) {
        this.oauth2ThirdClientService.enable(idList);
        return success();
    }

    /**
     * 禁用数据
     *
     * @param idList 主键集合
     * @return Void
     */
    @Operation(summary = "第三方客户端-禁用")
    @PostMapping("oauth2ThirdClientDisable")
    public R<Void> disable(@RequestParam("idList") Set<Long> idList) {
        this.oauth2ThirdClientService.disable(idList);
        return success();
    }
}

